package com.onetoall.yjt;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by shaomengjie on 2017/1/3.
 */

public class AnimationAdapter extends RecyclerView.Adapter<AnimationAdapter.MyVh> {
    private ArrayList<String> data;
    private Context context;
    private TranslateAnimation taLeft;
    private View view1;
    private View view2;
    private  MyVh myVh = null;
    public AnimationAdapter(ArrayList<String> data, Context context) {
        this.data = data;
        this.context = context;

        taLeft = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        taLeft.setDuration(1000);
    }

    @Override
    public MyVh onCreateViewHolder(ViewGroup parent, int viewType) {


            view1 = View.inflate(context, R.layout.item_textview,null);
            myVh = new MyVh(view1);

        return myVh;
    }

    @Override
    public void onBindViewHolder(MyVh holder, int position) {

        holder.textView.setText(data.get(position));

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyVh extends RecyclerView.ViewHolder {
      public   TextView textView;
        public MyVh(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.item_textView);
//            if (itemView == view1){
//                itemView.startAnimation(taLeft);
//            }
        }


    }

//    @Override
//    public int getItemViewType(int position) {
//        if (position == 0){
//            return 0;
//        }else {
//            return 1;
//        }
//    }

//    public void addData(int position) {
////      在list中添加数据，并通知条目加入一条
//
//
//
////        notifyItemInserted(position);
//    }
    //  删除数据
    public void removeData(int position) {
        data.remove(position);
        notifyItemRemoved(position);
    }



}
